//
//  ViewUtils.swift
//  ddx0513
//
//  Created by ejian  on 15/8/18.
//  Copyright (c) 2015年 jiang yongbin. All rights reserved.
//

import Foundation

class ViewUtils {
    class func popMessage(viewController: UIViewController, title: String, message: String) {
        var device : UIDevice = UIDevice.currentDevice()
        var systemVersion = device.systemVersion
        var iosVerion = (systemVersion as NSString).floatValue
        if(iosVerion < 8.0) {
            let alert = UIAlertView()
            alert.title = title
            alert.message = message
            alert.addButtonWithTitle("确定")
            alert.show()
        } else {
            var alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
            alert.addAction(UIAlertAction(title: "确定", style:.Default, handler: nil))
            viewController.presentViewController(alert, animated: true, completion: nil)
        }
    }
    
    class func heightForTextviewString(value: String, fontSize: CGFloat, width: CGFloat) -> CGFloat {
        var textview = UITextView(frame: CGRectMake(0, 0, width, 0))
        textview.font = UIFont.systemFontOfSize(fontSize)
        textview.text = value
        var deSize = textview.sizeThatFits(CGSizeMake(width, CGFloat.max))
        return deSize.height
    }
    
    class func heightForLabelString(text: NSString, fontSize: CGFloat, width: CGFloat) -> CGFloat {
        let size = CGSizeMake(width, 1000)
        
        let font = UIFont.systemFontOfSize(fontSize)
        let tdic = NSDictionary(object: font, forKey: NSFontAttributeName)
        let size2 = text.boundingRectWithSize(size, options: NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, attributes: tdic as [NSObject : AnyObject], context: nil).size
        
        return size2.height
    }
}